<?php
if ( !defined( "IN_OP" ) )
{
    exit( "You can't access this file directly..." );
}
require_once( "class_3d/CheckMode_3d.php" );
$gametype = intval( getvar( "gametype" ) );
$chk = new CheckMode_3d( $curruser['acl'], 1, $gametype );
$chk->checkShow3dPage();
$Show5NFlag = getShow35( $gametype );
$show3D3S = $chk->show3D3S;

if ( $show3D3S == 0 )
{
    exit();
}
$chkGametype = chkGametype( $gametype );
unset( $chk );
if ( $curruser['acl'] != 255 || $curruser['prev_id'] != 0 )
{
    $ui->showErrorPage( "您无执行的权限" );
    exit();
}
$ui = new UI_3D( true );
$tpl = new Template2();
$conf = new Config();
$tbl = $g_gametype_3d[$gametype]['en'];
$tblName = $g_gametype_3d[$gametype]['ch'];
$msg = "";
if ( ispost( ) )
{
    include( "class/function_3d.php" );
    $oldOpen = getvar( "openOld" );
    $newPaperDate = getvar( "newPaperDate" );
    $sqlAdd = "";
    $reUrl = "op.php?op=admin&fp=chgPaperDate_3d&gametype={$gametype}";
    if ( $newPaperDate == "0000-00-00" )
    {
        $sql = "DELETE FROM lotto_{$tbl} WHERE open = '0000-00-00'";
        getdb( $sql );
        $sql = "UPDATE bet_{$tbl} set rame = 2 where lotto_id IN(select id from lotto_{$tbl} WHERE open = '{$oldOpen}')";
        getdb( $sql );
        $sqlAdd = ", openbet = '0000-00-00 00:00:00', startbet = '0000-00-00 00:00:00', stopbet = '0000-00-00 00:00:00'";
        $sql = "UPDATE lotto_{$tbl} SET open='{$newPaperDate}' {$sqlAdd} WHERE open = '{$oldOpen}'";
        getdb( $sql );
        $tblDate = implode( "", explode( "-", $oldOpen ) );
        $sql = "DROP TABLE IF EXISTS `bettotal_{$tbl}_{$tblDate}`";
        getdb( $sql );
        getdb( "delete FROM rate_{$tbl} WHERE lotto_id IN (SELECT id FROM lotto_{$tbl} WHERE `open` = '0000-00-00')" );
        getdb( "delete FROM rates_{$tbl} WHERE lotto_id IN (SELECT id FROM lotto_{$tbl} WHERE `open` = '0000-00-00')" );
        if ( $chkGametype != 3 )
        {
            getdb( "delete FROM ratenum_{$tbl} WHERE lotto_id IN (SELECT id FROM lotto_{$tbl} WHERE `open` = '0000-00-00')" );
            getdb( "delete FROM ratenums_{$tbl} WHERE lotto_id IN (SELECT id FROM lotto_{$tbl} WHERE `open` = '0000-00-00')" );
        }
        $conf->set( "lotto_auto{$tbl}Msg", "无相关讯息" );
        $msg = "报表日期「{$oldOpen}」之资料异动为「{$newPaperDate}」完成(相关注单亦删除成功)!!";
    }
    else
    {
        diemsg( "只能将报表日改为0000-00-00", "不正确的日期格式", $reUrl );
    }
}
$rs = getdb( "select open,min(round),max(round),count(round) from lotto_{$tbl} where open != '0000-00-00' GROUP BY open order by open DESC" );
if ( $rs->eof )
{
    $list = "<div class='msgBox-Now' style='font-size:16px;text-align:center;padding:20px;width:758px;'>{$tblName} 目前无相关期数资料</div>";
}
else
{
    $paperVal = $rs->f[0];
    $list = "<form action=\"op.php?op=admin&fp=chgPaperDate_3d\" method=\"post\" onsubmit=\"return checkForm(this);\">";
    $list .= "<input type=\"hidden\" value=\"{$gametype}\" name=\"gametype\" />";
    $list .= "将<select name=\"openOld\" id=\"openOld\">";
    while ( !$rs->eof )
    {
        $list .= "<OPTION value='{$rs->f[0]}'>第 {$rs->f[1]}~{$rs->f[2]} 期，共{$rs->f[3]}期&nbsp;&nbsp;{$rs->f[0]}</OPTION>";
        $rs->movenext();
    }
    $list .= "</select>";
    $list .= " 报表日期 更新为 <input type=\"text\" value=\"{$paperVal}\" name=\"newPaperDate\" id=\"newPaperDate\" size=\"10\" />";
    $list .= "<a href=\"#\" onclick=\"javascript:showCalendarById('newPaperDate')\"><img align=absmiddle src=\"class/calendar/calendar.png\"  border=0 alt=\"\"></a>";
    $list .= "<input type=\"reset\" value=\"重设\" /><input type=\"submit\" value=\"确定\" />";
    $list .= "<br /><br /><span class=c4>※※请注意※※ 报表日期 更新为「0000-00-00」表示取消该日所有开奖期数 ※※</span>";
}
$jslink = "\n<script language=\"JavaScript\">\nfunction checkForm(frm){\n  if(confirm('确定要将报表日期「'+frm.openOld.value+'」之资料异动为「'+frm.newPaperDate.value+'」吗')){\n    return true;\n  }else{\n    return false;\n  }\n}\n</script>";
$ui->set( "jslink", $jslink );
$ui->header();
$ui->load( "calendar_js", "calendar_js.htm" );
$ui->show( "calendar_js" );
$menustradd = "<a href=\"op.php?op=admin&fp=history_3d&gametype={$gametype}\">回开奖列表</a>";
echo title( "{$tblName} 开奖管理 - 报表期数异动", $menustradd );
if ( $msg )
{
    echo "<div class='bgClc_{$gametype}' style='text-align:center;padding:20px;width:758px;'>{$msg}</div>";
}
echo "<br />";
echo $list;
$ui->footer();
?>